import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
	history: createWebHistory(),
	routes: [
		{
			path: '/bi_frontend',
			name: 'Index',
			meta: {
				name: '首页',
				requireAuth: false
			},
			component: () => import('@/views/Layout.vue'),
			children: [
				{
					path: '/bi_frontend',
					component: () => import('@/views/home/Index.vue')
				},
				{
                    path: '/bi_frontend/userGuide',
                    name:'UserGuide',
                    meta: {
                        title: '用户指南',
						requireAuth: false
                    },
                    component: () => import('../views/UserGuide.vue')
                },
				{
                    path: '/bi_frontend/sysInfo',
                    name:'SysInfo',
                    meta: {
                        title: '系统架构',
						requireAuth: false
                    },
                    component: () => import('../views/SysInfo.vue')
                },
				{
                    path: '/bi_frontend/projectDynamics',
                    name:'ProjectDynamics',
                    meta: {
                        title: '项目动态',
						requireAuth: false
                    },
                    component: () => import('../views/ProjectDynamics.vue')
                },
			]
		},
		{
			path: '/bi_frontend/login',
			name: 'Login',
			meta: {
				name: '登录',
				requireAuth: false
			},
			// route level code-splitting
			// this generates a separate chunk (About.[hash].js) for this route
			// which is lazy-loaded when the route is visited.
			component: () => import('../views/Login.vue')
		},
		{
            path: '/bi_frontend/home',
            //路由到的地址(自定义)
            component: () => import('../views/HomeView.vue'),
            //引入组件，组件Home.vue所在路径
            //Home.vue是需要路由的vue组件
            name: 'Home', //组件名称
            meta: {
                redirect: true,
                name: '个人主页',
				title: '首页',
                requiresAuth: true // 将此路由标记为需要登录
            },
            redirect: '/bi_frontend/dashBoard',
			children: [
                {
                    path: '/bi_frontend/dashBoard',
                    name:'DashBoard',
                    meta: {
                        title: '仪表盘',
						requireAuth: true
                    },
                    component: () => import('../views/due/DashBoard.vue')
                },
                {
                    path: '/bi_frontend/dueDiligence',
                    name:'dueDiligence',
                    meta: {
                        title: '项目尽调',
                    },
					redirect: '/bi_frontend/project/add',
                    children: [
                        {
                            path: '/bi_frontend/project/add',
                            meta: {
                                title: '新增项目',
                            },
                            component: () => import('../views/due/AddProject.vue'),
							redirect: '/bi_frontend/addProject/upload',
							children: [
								{
									path: '/bi_frontend/addProject/upload',
									meta: {
										title: '上传项目信息',
									},
									component: () => import('../views/due/addProject/Upload.vue')
								},
								{
									path: '/bi_frontend/addProject/upload1',
									meta: {
										title: '上传项目信息',
									},
									component: () => import('../views/due/addProject/Upload.vue')
								},
								{
									path: '/bi_frontend/addProject/resultCheck',
									meta: {
										title: '识别结果检查',
									},
									component: () => import('../views/due/addProject/ResultCheck.vue')
								},
								{
									path: '/bi_frontend/addProject/resultQuery',
									meta: {
										title: '启动查询结果',
									},
									component: () => import('../views/due/addProject/ResultQuery.vue')
								},
								{
									path: '/bi_frontend/addProject/resultUpdate',
									meta: {
										title: '修订分析结果',
									},
									component: () => import('../views/due/addProject/ResultUpdate.vue')
								},
								{
									path: '/bi_frontend/addProject/reportUPdate',
									meta: {
										title: '修订尽调报告',
									},
									component: () => import('../views/due/addProject/ReportUpdate.vue')
								},
								{
									path: '/bi_frontend/addProject/taskSummary',
									meta: {
										title: '尽调任务小结',
									},
									component: () => import('../views/due/addProject/TaskSummary.vue')
								},
							]
                        },
						{
                            path: '/bi_frontend/project/history',
                            meta: {
                                title: '历史项目',
                            },
                            component: () => import('../views/due/HistoryProject.vue')
                        },
                        {
                            path: '/bi_frontend/config/reportTemplate',
                            meta: {
                                title: '尽调报告模板配置',
                            },
                            component: () => import('../views/due/ReportTemplate.vue')
                        },
                        {
                            path: '/bi_frontend/config/dataWarehouse',
                            meta: {
                                title: '尽调数据仓库配置',
                            },
                            component: () => import('../views/due/DataWarehouse.vue')
                        },
                        {
                            path: '/bi_frontend/config/aiTemplate',
                            meta: {
                                title: '尽调AI模板配置',
                            },
                            component: () => import('../views/due/AITemplate.vue')
                        }
                    ]
                },
				{
                    path: '/bi_frontend/dataDictionary',
                    name:'DataDictionary',
                    meta: {
                        title: '数据字典',
						requireAuth: true
                    },
                    component: () => import('../views/DataDictionary.vue')
                },
				{
                    path: '/bi_frontend/houseEstimation',
                    name:'HouseEstimation',
                    meta: {
                        title: '住宅估值',
						requireAuth: true
                    },
                    component: () => import('../views/HouseEstimation.vue')
                },
				{
                    path: '/bi_frontend/dealConfirmation',
                    name:'DealConfirmation',
                    meta: {
                        title: '成交确认书',
						requireAuth: true
                    },
                    component: () => import('../views/due/DealConfirmation.vue')
                },
				{
                    path: '/bi_frontend/personalLoand/dstribute',
                    name:'PersonalLoandDstribute',
                    meta: {
                        title: '个贷调解分发',
						requireAuth: true
                    },
                    component: () => import('../views/personalLoanMediation/PersonalLoandDstribute.vue')
                },
				{
                    path: '/bi_frontend/personalLoand/detail',
                    name:'PersonalLoandDetail',
                    meta: {
                        title: '个贷调解分发详情',
						requireAuth: true
                    },
                    component: () => import('../views/personalLoanMediation/PersonalLoandDetail.vue')
                },
                {
                    path: '/bi_frontend/portrait/customer',
                    name:'CustomerPortrait',
                    meta: {
                        title: '客户画像',
						requireAuth: true
                    },
                    component: () => import('../views/portrait/CustomerPortrait.vue'),
                },
                {
                    path: '/bi_frontend/portrait/customer2',
                    name:'CustomerPortrait2',
                    meta: {
                        title: '客户画像',
						requireAuth: true
                    },
                    component: () => import('../views/portrait/CustomerPortrait.vue'),
                },
				{
					path: '/bi_frontend/portrait/customer/detail',
					meta: {
						title: '客户画像详情',
					},
					component: () => import('../views/portrait/CustomerPortraitDetail.vue')
				},
				{
                    path: '/bi_frontend/assetTagging',
                    name:'AssetTagging',
                    meta: {
                        title: '资产标签化',
						requireAuth: true
                    },
                    component: () => import('../views/assetTagging/AssetTagging.vue'),
					redirect: '/bi_frontend/assetTagging/upload',
					children: [
						{
							path: '/bi_frontend/assetTagging/upload',
							meta: {
								title: '上传项目信息',
							},
							component: () => import('../views/assetTagging/AssetTaggingUpload.vue')
						},
						{
							path: '/bi_frontend/assetTagging/aiPrompt',
							meta: {
								title: '项目转换结果修改',
							},
							component: () => import('../views/assetTagging/AssetTaggingAiPrompt.vue')
						},
						{
							path: '/bi_frontend/assetTagging/aiResult',
							meta: {
								title: '资产标签化AI结果',
							},
							component: () => import('../views/assetTagging/AssetTaggingAiResult.vue')
						},
						{
							path: '/bi_frontend/assetTagging/result',
							meta: {
								title: '资产标签化结果',
							},
							component: () => import('../views/assetTagging/AssetTaggingResult.vue')
						},
						{
							path: '/bi_frontend/addProject/reportUPdate',
							meta: {
								title: '修订尽调报告',
							},
							component: () => import('../views/due/addProject/ReportUpdate.vue')
						},
						{
							path: '/bi_frontend/addProject/taskSummary',
							meta: {
								title: '尽调任务小结',
							},
							component: () => import('../views/due/addProject/TaskSummary.vue')
						},
					]
                },
				{
                    path: '/bi_frontend/userMgt',
                    name:'UserMgt',
                    meta: {
                        title: '用户管理',
						requireAuth: true
                    },
                    component: () => import('../views/UserManagement.vue')
                },
                {
                    path: '/bi_frontend/remoteDue',
                    name: 'RemoteDue',
                    meta: {
                        title: '远程线上尽调',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/RemoteDue.vue')
                },
				{
                    path: '/bi_frontend/regroup',
                    name: 'Regroup',
                    meta: {
                        title: '重整重组',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/Regroup.vue')
                },
				{
                    path: '/bi_frontend/regroup2',
                    name: 'Regroup2',
                    meta: {
                        title: '重整重组',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/Regroup.vue')
                },
				{
                    path: '/bi_frontend/regroup3',
                    name: 'Regroup3',
                    meta: {
                        title: '重整重组',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/Regroup.vue')
                },
				{
                    path: '/bi_frontend/regroup4',
                    name: 'Regroup4',
                    meta: {
                        title: '重整重组',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/Regroup.vue')
                },
				{
                    path: '/bi_frontend/regroup5',
                    name: 'Regroup5',
                    meta: {
                        title: '重整重组',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/Regroup.vue')
                },
				{
                    path: '/bi_frontend/regroup6',
                    name: 'Regroup6',
                    meta: {
                        title: '重整重组',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/Regroup.vue')
                },
				{
                    path: '/bi_frontend/regroup7',
                    name: 'Regroup7',
                    meta: {
                        title: '重整重组',
                        requireAuth: true
                    },
                    // route level code-splitting
                    // this generates a separate chunk (About.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    component: () => import('../views/due/Regroup.vue')
                },
            ]
        },
    ],
})

// 挂载路由导航守卫：to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作
// router.beforeEach((to, from, next) => {
// 	console.log('路由打印');
	
// 	console.log(to);
// 	console.log(from);
// 	next();
// })

// 挂载路由导航守卫：to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作
router.beforeEach((to, from, next) => {
	// console.log('路由');
	// console.log(to);
	// 路由meta中配置了requireAuth为true的或者meta中没有配置requireAuth需要校验登录状态，只有requireAuth配置为false的才不用登录状态校验
	//const tokenStr = sessionStorage.getItem('token');
	//const tokenStr = localStorage.getItem('token');
	// console.log('路由tokenStr： '+tokenStr);
	// if (to.meta.requireAuth || to.meta.requireAuth === undefined) { 
	// 	if(!tokenStr) {
	// 		return next('/bi_frontend/login')
	// 	} else {
	// 		return next();
	// 	}
	// } else {

	// 	if(to.path === '/bi_frontend/login' && tokenStr) {
	// 		return next('/bi_frontend/home');
	// 	}
	// 	next()
	// }

	return next();
})
export default router
